#include "Include.h"
#include "Terrain.h"

#include "Terrain.h"



/*
void jeu()
{
    int terrain[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR];
    int i, j;
    for (i=0;i<NB_BLOCS_LARGEUR;i++)
    {
        for(j=0;j<NB_BLOCS_HAUTEUR;j++)
        {
            terrain[0][j] = MUR;
            terrain[NB_BLOCS_LARGEUR - 1][j] = MUR;
            terrain[i][0] = MUR;
            terrain[i][NB_BLOCS_HAUTEUR - 1] = MUR;
            if (i%2==0 && j%2==0)
                terrain[i][j] = MUR;

        }
    }
    printf("\n");
    for (i=0;i<NB_BLOCS_LARGEUR;i++)
    {
        for(j=0;j<NB_BLOCS_HAUTEUR;j++)
        {
            printf(" %d ", terrain[i][j]);

        }printf ("\n");
    }

}
*/

const char terGetXY(const terrain *ter, const int x, const int y)
{
	assert( x>=0) ;
	assert( y>=0) ;
	assert( x<ter->largeur) ;
	assert( y<ter->hauteur) ;
	return ter->tabTerrain[y][x];
}

void terSetXY(const terrain *ter, const int x, const int y, const char val)
{
	assert( x>=0) ;
	assert( y>=0) ;
	assert( x<ter->largeur ) ;
	assert( y<ter->hauteur ) ;
	ter->tabTerrain[y][x] = val;
}


const int getDimX(const terrain *ter)
{
	return ter->largeur;
}

const int getDimY(const terrain *ter)
{
	return ter->hauteur;
}

void libTerrain(terrain *ter)
{
	int y;

	for (y=0; y<ter->hauteur; y++)
		free(ter->tabTerrain[y]);
	free(ter->tabTerrain);

	ter->largeur = 0;
	ter->hauteur = 0;
	ter->tabTerrain = NULL;
}

void initTerrain(terrain *ter)
{
	int x,y;

    const char terrain_defaut[12][21] =
    { {VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,},
      {VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VID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DE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,},
      {VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,},
      {VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,VIDE,} };




    ter->largeur = 20;
	ter->hauteur = 12;

	ter->tabTerrain = (char **)malloc(sizeof(char *)*ter->hauteur);
	for (y=0; y<ter->hauteur; y++)
		ter->tabTerrain[y] = (char *)malloc(sizeof(char)*ter->largeur);

    for(y=0;y<ter->hauteur;++y)
		for(x=0;x<ter->largeur;++x)
			ter->tabTerrain[y][x] = terrain1[y][x];
}


int terEstPositionPersoValide(const terrain *pTer, const int x, const int y)
{
	if (x>=0
     && x<pTer->largeur
     && y>=0
     && y<pTer->hauteur
     && pTer->tabTerrain[y][x]!=(BLOC||BOMBE))
		return 1;
	else
		return 0;
}



/* int calculNbCasesVides(&terrain) PAS FINI
{
    for(i=NB_BLOCS_HAUTEUR;i>0;i--)
    {
        (NB_BLOCS_HAUTEUR*NB_BLOCS_LARGEUR) - (2* NB_BLOCS_HAUTEUR + 2* NB_BLOCS_LARGEUR - 4)

*/

